//
//  NSString+QTool.m
//  55likeLibDemo
//
//  Created by 55like on 2017/9/11.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "NSString+QTool.h"

@implementation NSString (QTool)


- (CGSize)SIZEwF:(CGFloat )font W:(CGFloat)maxW
{
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:font];
    CGSize maxSize = CGSizeMake(maxW, 0x1.fffffep+127f
                                );
    
    // 获得系统版本
    if ( ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)) {
        return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    } else {
        return [self sizeWithFont:[UIFont systemFontOfSize:font] constrainedToSize:maxSize];
    }
}

- (CGFloat)HEIGHTwF:(CGFloat )font W:(CGFloat)maxW{
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:font];
    CGSize maxSize = CGSizeMake(maxW, 0x1.fffffep+127f
                                );
    
    // 获得系统版本
    if ( ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)) {
        return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.height;
    } else {
        return [self sizeWithFont:[UIFont systemFontOfSize:font] constrainedToSize:maxSize].height;
    }
}


- (CGFloat)HEIGHTwaF:(UIFont* )font W:(CGFloat)maxW{
    
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = font;
    CGSize maxSize = CGSizeMake(maxW, 0x1.fffffep+127f
                                );
    
    // 获得系统版本
    if ( ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)) {
        return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.height;
    } else {
        return [self sizeWithFont:font constrainedToSize:maxSize].height;
    }
    
}
-(CGFloat)widthWithFont:(CGFloat )font
{
    UIFont*zmfont=[UIFont systemFontOfSize:font];
    NSDictionary *attrs = @{NSFontAttributeName : zmfont};
    
    CGSize maxsize=CGSizeMake(MAXFLOAT, font);
    return [self boundingRectWithSize:maxsize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.width;
}
//更改过行间距算高度
- (CGFloat)changeLineSpaceForLabelWithSpace:(float)space labW:(CGFloat)w font:(UIFont *)font{
    
    NSString *labelText = self;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:space];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, w, 0)];
    lab.attributedText = attributedString;
    lab.numberOfLines = 0;
    lab.font = font;
    [lab sizeToFit];
    
    CGFloat h = 0;
    
    h = lab.frameHeight;
    
    //    lab = nil;
    
    
    return h;
    
}




@end
